//
//  HomeViewController.m
//  微博2期
//
//  Created by J on 15/11/17.
//
//

#import "HomeViewController.h"
#import "TitleMenuViewController.h"
#import "DropDownMenu.h"
@interface HomeViewController ()

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    NSLog(@"%@",self.view.window);//null
    
    //设置导航栏内容
    //设置左边返回按钮

    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(friendSearch) image:@"navigationbar_friendsearch" highImage:@"navigationbar_friendsearch_highlighted"];
    
    //设置右边更多按钮

    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(pop) image:@"navigationbar_pop" highImage:@"navigationbar_pop_highlighted"];
    
    //中间标题按钮
    UIButton * titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    titleButton.width = 150;
    titleButton.height = 30;
//    titleButton.backgroundColor = RamdomColor;
    //设置图片和文字
    //按钮设置文字要用状态的方式
    [titleButton setTitle:@"首页" forState:UIControlStateNormal];
    [titleButton setTitleColor: [UIColor blackColor] forState:UIControlStateNormal];
    titleButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [titleButton setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
//    titleButton.imageView.backgroundColor = [UIColor redColor];
//    titleButton.titleLabel.backgroundColor = [UIColor redColor];
    titleButton.imageEdgeInsets = UIEdgeInsetsMake(0, 70, 0, 0);//设置图片的位置
    titleButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 50);
    self.navigationItem.titleView = titleButton;
    //如果图片的某个方向上不规则, 比如有凸起那么这个方向就不能拉伸
    //监听标题点击
    [titleButton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];

//   UITextField * textField  = [[UITextField alloc]init];
//    
//    textField.width  = 100;
//    textField.height = 50;
//    textField.backgroundColor = [UIColor orangeColor];
//
//    [self.view addSubview:textField];
    
    
    UIView * grayView=  [[UIView alloc]init];
    grayView.width = 200;
    grayView.height = 70;
    grayView.x = 20;
    grayView.y = 70;
    grayView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:grayView];
    
    
    UIButton * btn = [[UIButton alloc]init];
    
    btn.x= 110;
    btn.y = 30;
    btn.width = 100;
    btn.height  = 30;
    btn.backgroundColor = [UIColor orangeColor];
    [btn addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [grayView addSubview:btn];
    
}
- (void)titleClick:(UIButton*)button{
    //显示下拉菜单
   DropDownMenu* menu =  [DropDownMenu menu];
    
    TitleMenuViewController * vc= [[TitleMenuViewController alloc]init];
    vc.view.height = 44*3;
    vc.view.width = 150;

    menu.contentViewcontroller = vc;
     // 显示
    [menu showFrom:button];
    
  }


- (void)friendSearch{
    //这里sel本身就是一个导航控制器 self.navigationController ==null
}

- (void)pop{
    [self.navigationController popToRootViewControllerAnimated:YES];//返回根控制器
    


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
